﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Web;

namespace Interfleet.SE.UICompiler.Core.ClosureCompilerREST
{
    /// <summary>
    /// Compiler agent for the Closure Compiler REST API.
    /// </summary>
    public class CCRESTCompilerAgent : CompilerAgent
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="arguments"><see cref="Arguments"/> for compilation</param>
        /// <seealso cref="Arguments"/>
        public CCRESTCompilerAgent(Arguments arguments)
            : base(
            arguments, 
            new CCRESTArgumentBuilder(arguments),  
            new CCRESTResultBuilder(arguments))
        { }

        /// <summary>
        /// Compiles the javascripts using the REST API
        /// </summary>
        /// <returns></returns>
        public override CompileResult Compile()
        {
            var postData = ArgumentBuilder.Build();
            var response = CCRESTCaller.Call(postData);
            return ResultBuilder.Build(response, DateTime.Now);
            
        }
    }
}
